
Date.prototype.format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
angular.module('starter', ['ionic', 'starter.controllers','starter.services','app.directives','com.xbstar.jfhttp','com.xbstar.packge','com.xbstar.user','com.xbstar.im','com.xbstar.msg', 'ng-showdown','ionic-datepicker'])

.run(function($ionicPlatform,$rootScope,$state, JFIM,MSGService) {
  $rootScope.navTo=function(state){
    $state.go(state);
  }
   var userId=localStorage.getItem("userId");
     $rootScope.noReadArr={};
    if(userId){
      JFIM.registIMHandle("ws://106.14.30.199:8080/ws",userId,function(ss){
        MSGService.onMsgReceive(ss);
      });
      MSGService.findAll(userId);
          //TODO 极光推送连接
    }    
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  
})})

.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider, $showdownProvider,ionicDatePickerProvider) {
        //  $ionicConfigProvider.views.maxCache(0);
        $ionicConfigProvider.platform.ios.tabs.style('standard'); 
        $ionicConfigProvider.platform.ios.tabs.position('bottom');
        $ionicConfigProvider.platform.android.tabs.style('standard');
        $ionicConfigProvider.platform.android.tabs.position('standard');
        $ionicConfigProvider.platform.ios.navBar.alignTitle('center'); 
        $ionicConfigProvider.platform.android.navBar.alignTitle('center');
        $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-chevron-left');
        $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-chevron-left');	
        $ionicConfigProvider.platform.ios.views.transition('ios'); 
        $ionicConfigProvider.platform.android.views.transition('android');
         $showdownProvider.setOption("headerLevelStart", 3);
         var datePickerObj = {
          inputDate: new Date(),
          titleLabel: '选择合适的时间',
          setLabel: '确定',
          todayLabel: '今日',
          closeLabel: '取消',
          mondayFirst: false,
          weeksList: [ "周日","周一", "周二", "周三", "周四", "周五", "周六"],
          monthsList: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
          templateType: 'modal',
          from: new Date(),
          showTodayButton: false,
          dateFormat: 'yyyy年MM月dd日 ',
          closeOnSelect: false,
          disableWeekdays: []
        };
        ionicDatePickerProvider.configDatePicker(datePickerObj);
       
        
  $stateProvider
  .state('tab', {
    url: '/tab',
    abstract: true,
    templateUrl: 'templates/tabs.html'
  })

  // Each tab has its own nav history stack:

  .state('tab.dash', {
    url: '/dash',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl'
      }
    }
  })
  /**
   * 搜索
   */
    .state('tab.search', {
    url: '/search',
    views: {
      'tab-dash': {
        templateUrl: 'templates/search.html',
        controller: 'searchCtrl'
      }
    }
  })
  /**
   * 搜索结果
   */
     .state('searchinfo', {
    url: '/searchinfo/:id',
        templateUrl: 'templates/searchinfo.html',
        controller: 'searchinfoCtrl'
    
    })
 /**
  * 城市路线列表
  */
    .state('cityrouteinfo', {
   url: '/cityrouteinfo/:id',
       templateUrl: 'templates/cityrouteinfo.html',
       controller: 'searchinfoCtrl'
   
   })
    /**
    评论
    */
     .state('comment', {
      url: '/comment/:id',
          templateUrl: 'templates/comment.html',
          controller: 'CommentCtrl'
      
    })
  /**
   * 线路行程详情
   */
  .state('routetrip', {
    url: '/routetrip/:id',
        templateUrl: 'templates/routetripinfo.html',
        controller: 'RouteTripInfoCtrl'
    
  })
  /**
   * 线路评价详情
   */
  .state('routecoment', {
    url: '/routecoment/:id',
        templateUrl: 'templates/routecomment.html',
        controller: 'RouteCommentCtrl'  
  })
 /**
   * 线路费用详情
   */
  .state('routecost', {
    url: '/routetrip/:id',
        templateUrl: 'templates/costDetailP.html',
        controller: 'CostDetailPCtrl'
    
  })
  /**
   * 线路退订政策
   */
  .state('routeback', {
    url: '/routeback/:id',
        templateUrl: 'templates/backBookP.html',
        controller: 'RouteBackCtrl'
    
  })
  /**
   * 预订时间
   */
   .state('booktime', {
    url: '/booktime/:id',
        templateUrl: 'templates/booktime.html',
        controller: 'BookTimeCtrl'
    
  })
   .state('tab.routeinfo', {
    url: '/routeinfo/:id',
    views: {
      'tab-dash': {
        templateUrl: 'templates/routeinfo.html',
        controller: 'RoutInfoCtrl'
      }
    }
  })

  .state('tab.chats', {
      url: '/chats',
      views: {
        'tab-chats': {
          templateUrl: 'templates/tab-chats.html',
          controller: 'ChatsCtrl'
        }
      }
    })
    .state('chat-detail', {
      url: '/chats/:sessionId',
          templateUrl: 'templates/chat-detail.html',
          controller: 'ChatDetailCtrl'
    })

  .state('tab.account', {
    url: '/account',
    views: {
      'tab-account': {
        templateUrl: 'templates/tab-account.html',
        controller: 'AccountCtrl'
      }
    }
  })
  .state('tab.schedule', {
    url: '/schedule',
    views: {
      'tab-schedule': {
        templateUrl: 'templates/schedule.html',
        controller: 'ScheduleCtrl'
      }
    }
  })
  /**
   * 微信登陆
   */
  .state('weilogin', {
    url: '/weilogin',
    templateUrl: 'templates/weilogin.html',
    controller: 'WeiLoginCtrl'
  });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/tab/dash');

});
